<template>
  <div>
    <div class="PieBorderRadius" :id="main_id"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "PieBorderRadius",
  props:{
    list:Array,
  },
  data() {
    return {
      main_id: "mian" + Math.random(),
      pieDataList:this.list,
      myDatalist:[],
    };
  },
  //监听外部参数实时更新子组件内部变量
  watch: {
    list: {
      handler(newValue, oldValue) {
        this.pieDataList = newValue;
      },
      immediate: true,
    },
  },
  mounted() {
    //页面加载完成之后要执行的操作放在这里
    this.formatData();
  },
  methods: {
    formatData(){
      let datalist = this.pieDataList;
      let pielist = [];
      datalist.forEach((item)=>{
        let dataitem = {};
        dataitem.value = item.enterprise_count;
        dataitem.name = item.industry_name;
        pielist.push(dataitem);
      });
      this.myDatalist = pielist;
      console.log(pielist)
      this.initEchart();
    },
    initEchart() {
      var chartDom = document.getElementById(this.main_id);
      var myChart1 = echarts.init(chartDom);
      var _this = this;

      var option = {
        title: {
          text: "企业所属行业",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "行业分类",
            type: "pie",
            radius: "50%",
            data: _this.myDatalist, //{value:0,name:""}
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      //绘制图表
      myChart1.setOption(option);
    },
  },
};
</script>

<style scoped>
.PieBorderRadius {
  min-width: 300px;
  max-width: 600px;
  min-height: 600px;
  max-height: 900px;
}
</style>